{% init page_max = 0 %}
{% init page_size = 20 %}
{% init page_url = "?page=" %}

{% if "page_totalsize" in globals() %}
    {% set-global page_total = page_totalsize %}
{% end %}

{% if "page_total" in globals() %}
    {% set-global page_max = int(math.ceil(page_total/page_size)) %}
{% end %}

{% if page_max >= 0 %}
    <div class="pagenation">        
        <a class="x-page-link" href="{{page_url}}1">首页</a>

        {% if page <= 1 %}
            <a class="x-page-link disabled">上一页</a>
        {% else %}
            <a class="x-page-link" href="{{page_url}}{{page-1}}">上一页</a>
        {% end %}

        {% for j in range(max(1, page-2), page) %}
            <a class="x-page-link desktop-only-inline" href="{{page_url}}{{j}}">{{j}}</a>
        {% end %}

        <!-- 当前页 -->
        <a class="x-page-link active" href="#">{{page}}</a>
        
        {% for j in range(page+1, int(min(page+3, page_max+1))) %}
            <a class="x-page-link desktop-only-inline" href="{{page_url}}{{j}}">{{j}}</a>
        {% end %}

        {% if page >= page_max %}
            <a class="x-page-link disabled">下一页</a>
        {% else %}
            <a class="x-page-link" href="{{page_url}}{{page+1}}">下一页</a>
        {% end %}

        <a class="x-page-link" href="{{page_url}}{{page_max}}">尾页</a>
    </div>
{% end %}
